Skip to content

feat(lk): write evals and session labels under --user-auth - #1153

Open
jmcclanahan wants to merge 3 commits into
jakemcclanahan/eval-readsfrom
jakemcclanahan/eval-writes
Open

jmcclanahan wants to merge 3 commits into
jakemcclanahan/eval-readsfrom
jakemcclanahan/eval-writes

Conversation

@jmcclanahan

Copy link
Copy Markdown

Stacked on #1152 (eval reads), which is stacked on #1146. Merge order: #1146 → #1152 → this.

What

Lets a person or coding agent signed in with --user-auth write and ship evals from lk: check a definition, create an eval, save a draft, publish it, roll it back. It also manages session labels (the intents and outcomes an LLM assigns to each session).

  • lk agent eval validate | create | update | save | discard | publish | rollback | delete | undelete
  • lk agent eval defaults set --file FILE (the project's judge defaults)
  • lk agent eval label create | update | delete | undelete, lk agent eval label settings set
  • Definitions come from --file FILE (or - for stdin), a JSON object, the same one get --json prints

Why

The Public API's EvalService writes are in production (livekit/public-api-server#212, #213), but lk could only read evals (#1152). Authoring from a file makes evals scriptable, and a coding agent can edit them.

How

  • Asks before paid work: publish, rollback, undelete and label create/undelete start LLM judging or labeling, so they ask first, matching the MCP tools' confirm: true. Discard asks too, since the draft is lost. --yes skips the question; a run that can't prompt refuses and sends nothing.
  • Draft etags: save, discard and publish take --etag to refuse when someone else changed the draft. Without it, lk reads the current draft and acts on it. A stale etag (Aborted) says to re-read; a stale base revision (FailedPrecondition) prints the diff to run and --allow-stale-base. To tell the two apart, APIError now keeps the envelope's gRPC code.
  • Field violations: a refused definition lists each wrong field under the message. FieldViolations and the cloudAPIError change are copied from feat(lk): lk agent builder manages Agent Builder agents under --user-auth #1136, so whichever of the two merges second resolves the conflict by taking one copy.
  • Settings merge: label settings set reads the settings, changes only the flags given, and sends them all, because the API resets any field left out.
  • Definitions verbatim: a definition goes up as written, never through the generated type. A whole get --json response is refused, with the jq that extracts the definition.

Testing

  • go build ./..., go vet ./..., go test ./... and go test -race ./cmd/lk ./pkg/public/... pass.
  • Unit tests cover each request body, including unknown definition fields surviving, the etag and stale-base paths, the refusals without --yes, the violations listing, and the settings merge.
  • New testscript eval-writes-with-user-auth.txtar runs the binary through validate, create, save, publish (refused without --yes, then with it), label create and settings set. The request log shows that a refused change sends nothing.
  • Not yet run: golangci-lint (CI runs it), and the commands against staging.

🤖 Generated with Claude Code

jmcclanahan and others added 3 commits December 1, 2026 11:15
Adds client calls for the Public API's eval writes: ValidateEval,
CreateEval, UpdateEval, SaveEvalDraft, DiscardEvalDraft,
PublishEvalDraft, RollbackEval, DeleteEval, UndeleteEval,
UpdateEvalDefaults, the session label writes and
UpdateSessionLabelSettings. Definitions go to the API verbatim.

APIError now keeps the error envelope's gRPC code, so a caller can tell a
stale draft etag (Aborted) from a stale base revision
(FailedPrecondition), and FieldViolations reads a BadRequest detail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adds lk agent eval validate|create|update|save|discard|publish|rollback|
delete|undelete, lk agent eval defaults set, lk agent eval label
create|update|delete|undelete and lk agent eval label settings set.

Publish, rollback, undelete and label create/undelete start LLM judging
or labeling, so they ask first, as the MCP tools do; discard asks too.
--yes skips the question, and a run that can't ask refuses. A refused
request lists the fields the API named.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jmcclanahan
jmcclanahan added this pull request to stack #1154 December 1, 2026 17:50
@jmcclanahan
jmcclanahan marked this pull request as ready for review December 1, 2026 18:40

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 4 potential issues.

1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

if err != nil {
return evalSave{}, err
}
return evalSave{definition: definition, etag: cmd.String("etag")}, nil

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Empty etag permits draft overwrite

With explicit --etag "", saveEvalDraft adopts the current draft’s etag instead of requiring no draft. It overwrites a draft created since the caller checked.

Learn more

The save request uses an empty etag for an eval without a draft. The CLI currently collapses an explicitly empty flag and an omitted flag into the same string. saveEvalDraft responds to either by reading the latest draft and using its etag, which satisfies the API check even when that draft was created after the caller last checked.

Example: A script reads a published eval with no draft and passes --etag "". A teammate saves a draft before the script runs save. The CLI fetches the teammate’s etag and replaces their draft rather than sending the empty etag and getting a conflict.

Recommended fix: Preserve whether --etag was set using cmd.IsSet("etag"). Auto-fetch the latest etag only when the flag is absent. Test an explicitly empty etag against an eval that now has a draft.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +935 to +939
current, err := client.GetSessionLabelSettings(ctx, projectID)
if err != nil {
return readAPIError(err, "a project's session label settings", projectReadAccess)
}
s := *current

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Concurrent label settings updates lost

When two setSessionLabelSettings calls read the same settings, the later write restores untouched fields from its stale snapshot. Both commands succeed, even though the later write erases the first command’s change.

Learn more

The CLI promises that fields without flags keep their values. UpdateSessionLabelSettings sends a full replacement, and the update request has no version precondition. That leaves the merged snapshot unprotected between the read and write.

Example: One operator raises the confidence threshold from 0.7 to 0.9 while another sets the minimum duration to 30 seconds. Both reads return 0.7. If the duration update writes second, it silently resets the threshold to 0.7.

Recommended fix: Use a server-side partial update, or add a version precondition to replacement writes and surface conflicts. A CLI-local lock cannot coordinate writers on different machines.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +559 to +563
if etag == "" {
_, draft, err := currentDraft(ctx, client, projectID, evalID)
if err != nil {
return evalWriteError(err, projectID, evalID)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 First draft discard blocks saving

After discarding an unpublished eval’s only draft, saveEvalDraft fails before writing a replacement. GetEval requires a draft or revision, and the eval now has neither.

Learn more

Creating an eval does not publish a revision, and DiscardEvalDraft removes the draft without changing the live revision. currentDraft treats a failed draft lookup as a reason to look up the published revision. That fallback cannot succeed for an eval with no versions: GetEval rejects even a successful metadata response without a version. The save request, in contrast, explicitly supports an empty etag when no draft exists.

Example: Create an eval, discard its draft before publishing, then run save with an edited definition. The CLI returns a lookup error and never sends the save request.

Recommended fix: In the save path, treat a draft lookup returning NotFound as a reason to send the save request with no etag. Let the save endpoint distinguish an unknown eval from an existing one without a draft, and test the create–discard–save sequence.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

}
return nil, fmt.Errorf("%s must hold a JSON object: %w", path, err)
}
_, hasEval := fields["eval"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Null accepted as a definition object

When a definition file contains null, readDefinitionFile accepts it instead of rejecting it. Go decodes null into a nil map without error, so the command sends a non-object definition.

Suggested change
_, hasEval := fields["eval"]
if fields == nil {
return nil, fmt.Errorf("%s must hold a JSON object", path)
}
_, hasEval := fields["eval"]

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant